package com.me.study.javaCore.jndi;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 * 
 *
 * @author ME
 * @date   2020/5/14
 */
public class TestJndiRmiClient {

    public static void main(String[] args) {
        try {
            System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
            System.setProperty(Context.PROVIDER_URL, TestJndiRmiSever.serverUrl);

            InitialContext ctx = new InitialContext();
            JndiServiceImpl jndiService = (JndiServiceImpl) ctx.lookup(TestJndiRmiSever.serverName);
            System.out.println("服务端默认的 personName：" + jndiService.fun());

            System.out.println();
            jndiService.setPersonName("jack");
            System.out.println("修改后的 personName：" + jndiService.fun());
        } catch (NamingException e) {
            e.printStackTrace();
        }
    }
}
